package linkedlistsetcode;

import bstsetcode.Set;



/**
 * @author noob
 * @version 1.0
 * @date 2021/3/18 9:57
 *
 * 使用我们自己实现的linkedlist
 */
public class LinkedListSet<E> implements Set<E> {
    private LinkedList2<E>  list;

    public LinkedListSet() {
        this.list = new LinkedList2<>();
    }

    @Override
    public void add(E e) {
        //实现set，不包含e元素，才添加---维持Set的特性
        if(!list.contains(e)){
            list.addFirst(e);
        }
    }

    @Override
    public void remove(E e) {
        list.removeElement(e);
    }

    @Override
    public boolean contains(E e) {
        return list.contains(e);
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }
}
